//
//  TEUltilities.m
//  ThaiExpress
//
//  Created by Le Quang Vinh on 7/15/13.
//  Copyright (c) 2013 Fruity. All rights reserved.
//

#import "TEUltilities.h"

@implementation TEUltilities

+ (BOOL)checkNetworking
{
    BOOL checkNetwork = YES;
    BOOL _isDataSourceAvailable = NO;
    if (checkNetwork) { // Since checking the reachability of a host can be expensive, cache the result and perform the reachability check once.
        checkNetwork = NO;
        
        Boolean success;
        const char *host_name = "google.com"; // your data source host name
        
        SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, host_name);
        SCNetworkReachabilityFlags flags;
        success = SCNetworkReachabilityGetFlags(reachability, &flags);
        _isDataSourceAvailable = success && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);
        CFRelease(reachability);
    }
    
    return _isDataSourceAvailable;
}

+ (NSString *)getPathImage:(NSString *)fileName withFolder:(NSString *)folder{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pathImage = [[documentsDirectory stringByAppendingPathComponent:folder]stringByAppendingPathComponent:fileName];
    
	return [NSString stringWithFormat:@"%@.jpg",pathImage];
}

@end
